package Offer.offer2017;

/**
 * Created by 雷文康 on 2018/1/6.
 */
public class Test42a {
    public static void main(String[] args) {
        char[] ch={'a','b','c','d','e','f','g'};
        reverse(ch,2);
    }

    public static void reverse(char[] ch, int num){
        if (ch == null || ch.length < num){
            return;
        }
        reverse(ch,0, num - 1);
        reverse(ch,num, ch.length - 1);
        reverse(ch, 0, ch.length - 1);
        for (int i = 0; i < ch.length; i++) {
            System.out.print(ch[i]);
            System.out.print(" ");
        }

    }

    private static void reverse(char[] ch, int start, int end){
        while (start < end){
            char temp = ch[start];
            ch[start] = ch[end];
            ch[end] = temp;
            start++;
            end--;
        }
    }
}
